﻿using ApplicationBase.Core.Logs;

namespace LogDashboard.Application.Model
{
    public class UowDataModel
    {
        public List<UnitOfWorkLog> uowLogs = new();
        public string Name { get; set; }
        public long Count { get; set; }
        public long MaxElapsed { get; set; }
        public long MinElapsed { get; set; }
        public double AverageElapsed { get; set; }

        public UowDataModel(List<UnitOfWorkLog> logs)
        {
            uowLogs = logs;
            Name = logs[0].Name;

            long min = logs[0].Elapsed;
            long max = logs[0].Elapsed;
            foreach (var log in logs)
            {
                if (min > log.Elapsed) min = log.Elapsed;
                
                if (max < log.Elapsed) max = log.Elapsed;
                
                Count++;
            }

            MaxElapsed = max; 
            MinElapsed = min;
            AverageElapsed = logs.Select(it => it.Elapsed).Average();
        }
    }
}
